﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace Workbench.Models
{
    public class PersistableModel : INotifyPropertyChanged, IEquatable<PersistableModel>
    {
        private long rowId;
        public long RowId
        {
            get { return rowId; }
            set { rowId = value; RaisePropertyChanged(); }
        }

        public virtual bool IsPersisted() { return RowId != 0; }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void RaisePropertyChanged([CallerMemberName]string propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public bool Equals(PersistableModel other)
        {
            if (other == null) return false;
            return rowId == other.rowId;
        }
 
        public override int GetHashCode()
        {
            return rowId.GetHashCode();
        }
    }
}
